package com.beiding.my.bomapping;

import com.beiding.my.bemapping.BeTypeMapper;
import com.beiding.my.bemapping.BeTypeMapperHolder;
import org.springframework.stereotype.Component;

@Component
public class StaticQuoteHolder {

    private static BeTypeMapperHolder beTypeMapperHolder;

    public StaticQuoteHolder(BeTypeMapperHolder beTypeMapperHolder) {
        StaticQuoteHolder.beTypeMapperHolder = beTypeMapperHolder;
    }

    public static QuoteDetails createQuoteDetails(Class holderBeType, Class targetBeType, String quoteName) {
        BeTypeMapper holderMapper = beTypeMapperHolder.getMapper(holderBeType);
        BeTypeMapper targetMapper = beTypeMapperHolder.getMapper(targetBeType);
        BeTypeMapper quoteMapper = beTypeMapperHolder.getQuoteMapper(targetBeType);

        QuoteDetails quoteDetails = new QuoteDetails();
        quoteDetails.holderTableName = holderMapper.getTableName();
        quoteDetails.holderIdColName = holderMapper.getFieldByName("id").getColName();
        quoteDetails.targetTableName = targetMapper.getTableName();
        quoteDetails.targetIdColName = targetMapper.getFieldByName("id").getColName();
        quoteDetails.quoteTableName = quoteMapper.getTableName();
        quoteDetails.holderFieldColName = quoteMapper.getFieldByName("_" + holderMapper.getName() + "_" + quoteName).getColName();
        quoteDetails.selfFieldColName = quoteMapper.getFieldByName("self").getColName();
        return quoteDetails;
    }

}
